package ai.people.netmon.framework.domain.archives.vo;

import ai.people.netmon.framework.domain.archives.entity.WorkOrder;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * 工单列表VO
 *
 * @author zhenglin
 * @date 2022/5/31
 */
@Data
@NoArgsConstructor
public class WorkOrderListVO {

    /**
     * 新消息提醒
     */
    private Boolean newMsgState;

    /**
     * 工单ID
     */
    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long id;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 描述
     */
    private String describe;

    /**
     * 工单状态类型
     */
    private Integer orderType;

    /**
     * 工单提交时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 工单回复时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    /**
     * 是否已被受理
     */
    private Boolean isAccept;

    /**
     * 受理人
     */
    private String acceptName;

    /**
     * 是否已被终止
     */
    private Boolean isStop;

    /**
     * 是否已完成
     */
    private Boolean isComplete;

    /**
     * 是否是操作人
     */
    private Boolean isOperator;

    public WorkOrderListVO(WorkOrder record, boolean isAccept, String acceptName, boolean isStop, boolean isComplete, boolean isOperator, boolean admin) {
        //如果是管理员则显示 hasNewMsgAdmin 字段
        this.newMsgState = admin ? record.getHasNewMsgAdmin() : record.getHasNewMsg();
        this.id = record.getId();
        this.userName = record.getCreatorName();
        this.userAvatar = null;
        this.describe = record.getDescribe();
        this.orderType = record.getOrderType();
        this.createTime = record.getCreateTime();
        this.updateTime = record.getUpdateTime();
        this.isAccept = isAccept;
        this.acceptName = acceptName;
        this.isStop = isStop;
        this.isComplete = isComplete;
        this.isOperator = isOperator;
    }
}
